<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class SysMenuRequest extends FormRequest
{
    protected array $scenes = [
        'add' => ['menu_name', 'menu_key', 'parent_key','menu_type','icon','api_url','router_path','page_path','methods','source','menu_attr','is_show','sort','status'],
        'edit' => ['id','menu_name', 'menu_key', 'parent_key','menu_type','icon','api_url','router_path','page_path','methods','source','menu_attr','is_show','sort','status'],
    ];
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'id' => 'required|integer',
            'menu_name' => 'required|min:2|max:50',
            'menu_type' => ['required', Rule::in(['0', '1', '2'])],
            'methods' => ['required', Rule::in(['POST', 'GET', 'PUT', 'DELETE'])],
            'source' => ['required', Rule::in(['system', 'create', 'generator'])],
            'is_show' => 'required|integer',
            'sort' => 'required|integer',
            'status' => 'required|integer',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'id.required' => '参数错误-0',
            'id.integer' => '参数错误-1',
            'menu_name.required' => '名称不能为空',
            'menu_name.min' => '名称格式不正确',
            'menu_name.max' => '名称格式不正确',
            'is_show.required' => '格式错误-1',
            'is_show.integer' => '格式错误-2',
            'sort.required' => '格式错误-3',
            'sort.integer' => '格式错误-4',
            'status.required' => '格式错误-5',
            'status.integer' => '格式错误-6',
        ];
    }
}
